package com.iplant.ams.service.po.dms.scada.status;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.po.dms.DMSDeviceLedger;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.join.multi.DBJoinMulti;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.base.utils.general.CalendarTool;

import java.io.Serializable;
import java.util.Calendar;

@DBBasePO(TableName = "dms_device_status", Schemas = DBSchemas.AMS, CheckName = {"DeviceID"},
        Code = false,Name = false,Active = false,Comment = "设备当前状态")
public class DMSDeviceCurrentStatus extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;

    @DBCondition
    @DBField(name = "DeviceID", Description = "设备AssetNo")
    public String AssetNo = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.Combine,ParamName2 = "StatusEQ")
    @DBField(Description = "设备当前状态")
    public int DeviceStatus = 0;


    @DBCondition
    @DBField(Description = "设备上次状态")
    public int DeviceStatusL = 0;



    @DBJoin(name = "ImageIcon", tableName = "dms_device_ledger", tableAsName = "d1", Schemas = DBSchemas.AMS, MainTableField = "DeviceID")
    public String ImageIcon = "";
    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "UDStartTime", ParamName2 = "EndTime")
    @DBField
    public Calendar ChangeDate = Calendar.getInstance();

    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "StartTime", ParamName2 = "UDEndTime")
    @DBField
    public Calendar UpdateDate = Calendar.getInstance();

    public DMSDeviceStatus CreateDeviceStatus(DMSDeviceLedger wDMSDeviceLedger) {
        DMSDeviceStatus wDeviceStatus = new DMSDeviceStatus();

        wDeviceStatus.ID = this.ID;
        wDeviceStatus.AssetNo = this.AssetNo;
        wDeviceStatus.Status = this.DeviceStatus;
        wDeviceStatus.StatusHistory = this.DeviceStatusL;
        wDeviceStatus.StatusTime = this.ChangeDate;
        wDeviceStatus.Duration = (int) CalendarTool.SubSeconds(Calendar.getInstance(), wDeviceStatus.StatusTime);
        wDeviceStatus.StatusTimeEnd = Calendar.getInstance();

        if (wDMSDeviceLedger != null) {
            wDeviceStatus.DeviceNo = wDMSDeviceLedger.Code;
            wDeviceStatus.DeviceName = wDMSDeviceLedger.Name;
            wDeviceStatus.DeviceID = wDMSDeviceLedger.ID;
            wDeviceStatus.ModelID = wDMSDeviceLedger.ModelID;
            wDeviceStatus.ModelName = wDMSDeviceLedger.StandardModelName;
            wDeviceStatus.ModelNo = wDMSDeviceLedger.StandardModelCode;
            wDeviceStatus.DeviceType = wDMSDeviceLedger.DeviceTypeID;
            wDeviceStatus.DeviceTypeName = wDMSDeviceLedger.DeviceTypeName;
            wDeviceStatus.DeviceTypeCode = wDMSDeviceLedger.DeviceTypeCode;
            wDeviceStatus.WorkShopID = wDMSDeviceLedger.WorkshopID;
            wDeviceStatus.WorkShopName = wDMSDeviceLedger.WorkshopName;
            wDeviceStatus.WorkShopCode = wDMSDeviceLedger.WorkshopCode;
            wDeviceStatus.FactoryID = wDMSDeviceLedger.FactoryID;
            wDeviceStatus.FactoryName = wDMSDeviceLedger.FactoryName;
            wDeviceStatus.FactoryCode = wDMSDeviceLedger.FactoryCode;
            wDeviceStatus.AreaID = wDMSDeviceLedger.WorkAreaID;
            wDeviceStatus.AreaNo = wDMSDeviceLedger.WorkAreaCode;
            wDeviceStatus.PositionText = wDMSDeviceLedger.WorkAreaName;
            wDeviceStatus.ImageIcon = wDMSDeviceLedger.ImageIcon;
            wDeviceStatus.Remark = wDMSDeviceLedger.Description;
        }
        return wDeviceStatus;
    }


    @JsonProperty("AssetNo")
    public String getAssetNo() {
        return AssetNo;
    }

    public void setAssetNo(String assetNo) {
        AssetNo = assetNo;
    }

    @JsonProperty("DeviceStatus")
    public int getDeviceStatus() {
        return DeviceStatus;
    }

    public void setDeviceStatus(int deviceStatus) {
        DeviceStatus = deviceStatus;
    }

    @JsonProperty("DeviceStatusL")
    public int getDeviceStatusL() {
        return DeviceStatusL;
    }

    public void setDeviceStatusL(int deviceStatusL) {
        DeviceStatusL = deviceStatusL;
    }

    @JsonProperty("ImageIcon")
    public String getImageIcon() {
        return ImageIcon;
    }

    public void setImageIcon(String imageIcon) {
        ImageIcon = imageIcon;
    }

    @JsonProperty("ChangeDate")
    public Calendar getChangeDate() {
        return ChangeDate;
    }

    public void setChangeDate(Calendar changeDate) {
        ChangeDate = changeDate;
    }

    @JsonProperty("UpdateDate")
    public Calendar getUpdateDate() {
        return UpdateDate;
    }

    public void setUpdateDate(Calendar updateDate) {
        UpdateDate = updateDate;
    }
}
